import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import VitePluginCompression from "vite-plugin-compression";

export default defineConfig({
  base: "/backstage/",
  build: {
    emptyOutDir: true, //打包前是否先清空原有打包文件
    minify: false, // 打包结果是否minify
    rollupOptions: {
      // vite打包是通过rollup来打包的
      output: {
        manualChunks: (id) => {
          // 将node_modules中的包打包为vendor文件
          if (id.indexOf("node_modules") > -1) {
            return "vendor";
          }
        },
      },
    },
  },

  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    VitePluginCompression(), //gzip 压缩
  ],
});
